package com.nameli.admin.controller;

import com.github.pagehelper.PageInfo;
import com.nameli.SIM.bean.query.FacultyQuery;
import com.nameli.SIM.bean.vo.FacultyVO;
import com.nameli.SIM.util.response.JsonResult;
import com.nameli.SIM.util.EmptyUtil;
import com.nameli.SIM.util.ReturnStatus;
import com.nameli.admin.service.FacultyService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author NAME-L
 * @Description 院系操作 控制层
 * @className FacultyController
 * @date 2021-11-15 10:43:54
 */
@RestController
@CrossOrigin
@RequestMapping("/faculty")
public class FacultyController {
    private static final Log log = LogFactory.getLog(FacultyController.class);

    @Autowired
    private FacultyService facultyService;

    @GetMapping("/index")
    public JsonResult queryAllByPage(@RequestParam("pageIndex") Integer pageIndex , @RequestParam("pageSize") Integer pageSize){
        log.info("enter into -----------> FacultyController - queryAllFaculty");
        JsonResult jsonResult = null;
        String errorCode = "";//返回状态码
        String errorMsg = "";//返回的提示信息
        if(EmptyUtil.isNotEmpty(pageIndex) && EmptyUtil.isNotEmpty(pageSize)){
            log.info("pageIndex:"+pageIndex+ "\t"+"pageSize:"+pageSize );
            log.info("check -----------> pageIndex & pageSize 不为空");
            PageInfo<FacultyVO> returnList = facultyService.queryAllFaculty(pageIndex, pageSize);
            errorCode = ReturnStatus.SUCCESS;
            errorMsg = "查询成功";
            jsonResult = JsonResult.returnMethod(errorCode, errorMsg, returnList);

        }else {
            log.info("check -----------> pageIndex & pageSize 为空");
            errorCode = ReturnStatus.DO_FAILED;
            errorMsg = "查询失败";
            jsonResult = JsonResult.withoutData(errorCode, errorMsg);
        }
        return jsonResult;
    }

    @GetMapping("/info/condition")
    public JsonResult queryByCondition(FacultyQuery facultyQuery ,  @RequestParam("pageIndex") Integer pageIndex , @RequestParam("pageSize") Integer pageSize){
        log.info("enter into -----------> FacultyController - queryAllFaculty");
        JsonResult jsonResult = null;
        String errorCode = "";//返回状态码
        String errorMsg = "";//返回的提示信息

        if(EmptyUtil.isNotEmpty(pageIndex) && EmptyUtil.isNotEmpty(pageSize) && EmptyUtil.isNotEmpty(facultyQuery)){
            log.info("pageIndex:"+pageIndex+ "\t"+"pageSize:"+pageSize );
            log.info("facultyQuery查询条件："+ facultyQuery);
            log.info("check -----------> pageIndex & pageSize & facultyQuery不为空");
            PageInfo<FacultyVO> returnList = facultyService.queryByCondition(facultyQuery ,pageIndex, pageSize);
            errorCode = ReturnStatus.SUCCESS;
            errorMsg = "查询成功";
            jsonResult = JsonResult.returnMethod(errorCode, errorMsg, returnList);
        }else {
            errorCode = ReturnStatus.DO_FAILED;
            errorMsg = "查询失败";
            jsonResult = JsonResult.withoutData(errorCode, errorMsg);
        }
        return jsonResult;
    }
}
